package chapter06.group;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class GroupingReducer extends Reducer<EmpBean, IntWritable, Text, IntWritable> {
    private Text keyOut = new Text();
    private IntWritable valueOut = new IntWritable();

    @Override
    protected void reduce(EmpBean key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        int count = 0;
        for (IntWritable value:
             values) {
            count += value.get();
        }
        valueOut.set(count);
        keyOut.set(key.getDeptNo());
        context.write(keyOut, valueOut);
    }
}
